<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Ionize, creative CMS
 *
 * @package		Ionize
 * @author		Ionize Dev Team
 * @license		http://ionizecms.com/doc-license
 * @link		http://ionizecms.com
 * @since		Version 0.9.0
 */

// ------------------------------------------------------------------------

/**
 * Ionize, creative CMS Article Controller
 *
 * @package		Ionize
 * @subpackage	Controllers
 * @category	Article
 * @author		Ionize Dev Team
 *
 */
 
class pr_tab_account_cl extends MY_admin 
{

	/**
	 * Fields on wich the htmlspecialchars function will not be used before saving
	 * 
	 * @var array
	 */
	/**
	 * Fields on wich no XSS filtering is done
	 * 
	 * @var array
	 */
	/**
	 * Constructor
	 *
	 */
	public function __construct()
	{
		parent::__construct();
		// product model
		$this->load->model('pr_fnc_model', '', true);
	}

	// ------------------------------------------------------------------------
	/**
	 * Default : Do nothing
	 *
	 */
	function index()
	{
		//point to pr_product view, then pr_product point to pr_product_list
		$this->output('pr_tab_account');
	}
	
	// get List product
	function get_list_pagination($page=1)
	{
		//$branchs	= $this->sibilling_model->get_by_field('branchs', 'id', $this->session->userdata('branchs_id'));
		if($this->input->post('num') != ''){
			$num = $this->input->post('num');
			$nb = ($this->input->post('nb')) ? $this->input->post('nb') : $num;
		}else{
			$num = 25;
			$nb = ($this->input->post('nb')) ? $this->input->post('nb') : $num;
		}
		
		$txt_filter = $this->input->post('keyword');
		
		if($txt_filter == ''){
			$keyword = '';
			$this->template['keyword'] = '';
		}else{
			$num = 25;
			$this->template['keyword'] = $txt_filter;
			$keyword = "WHERE lower(acc_name) like '%".strtolower($txt_filter)."%'";
		}
		//trace($txt_filter);
		// Minimum
		if ($nb < $num)	$nb = $num;
		
		$page 	= $page - 1;
		$offset = $page * $nb;
		
		$sql	= 	"SELECT * FROM tbl_account ".$keyword."
					ORDER BY acc_id DESC
					LIMIT ".$nb. " OFFSET ".$offset ;
			
		//trace($sql);				
		
		$products = $this->pr_fnc_model->get_by_sql($sql);
		$this->template['account'] = $products;
		//trace($odf_list);
		
		// Pagination
		$this->template['current_page'] = $page + 1;
		$this->template['nb'] = $nb;
		$this->template['option'] = $num;
		$this->template['port_list_count'] = $this->pr_fnc_model->count_by_sql("SELECT * FROM tbl_account ORDER BY acc_id DESC");
		
		$this->template['port_list_pages'] = ceil($this->template['port_list_count'] / $nb);
		$this->template['paginations']=$this->connect->paginations($this->template['port_list_pages'],$this->template['current_page']);
		
		$this->output('pr_tab_account');
	}
	function page_new_account(){
		$this->template['types']	= $this->pr_fnc_model->get_by_sql('SELECT * FROM tbl_type');
		$this->output('pr_tab_account_new');
	}
	//filter account by type
	function modelbyid($form)
	{			
		// Where
		$type_id = $this->input->post('type_id');		
		if($type_id != ""){
			$accounts=$this->template['accounts'] 	= $this->pr_fnc_model->get_by_sql('SELECT * FROM tbl_account WHERE type_id='.$type_id);
			///trace($accounts);
		}
		else
			$this->template['accounts']	= array();
			
		$this->template['type']		= "type";	
		$this->template['form']			= $form;
		
		$this->output('pr_tab_account_filter');
	}
	//get account
	/*function switchbymodel($form)
	{			
		// Where		
		if($this->input->post('sw_model') != ""){
			$sql = "SELECT * FROM tbl_account WHERE type_id='".$this->input->post('sw_model')."' order by acc_name";
			$this->template['get_names'] = $this->pr_fnc_model->get_by_sql($sql);		
		}else
			$this->template['get_names']	= array();

		$this->template['switch']		= "switch_name";	
		$this->template['form']			= $form;
		
		$this->output('pr_tab_account_filter');
	}*/
	
}//end class


/* End of file article.php */
/* Location: ./application/controllers/admin/article.php */